from renming.Renming import Renming
from utils.LoginUtils import UnifiedLogger
class Warehouse:
    def __init__(self, keywords:str, batchNum = 2000):
        self.keywords = keywords
        self.batchNum = batchNum
        self.logging = UnifiedLogger.get_logger()
    
    def initSpider(self):
        renming = Renming(self.keywords)
        renming.initialization()
        needPage = renming.totalPages
        self.addWarehouse(renming.getDataByPage, needPage)
        
    def addWarehouse(self, getDataByPage, needPage):
        while True:
            resultList = []
            while len(resultList) < self.batchNum:
                resultList.append(getDataByPage(needPage=needPage))
                needPage -= 1
                if needPage <= 0:
                    return resultList
            self.logging.info("获取匹配数据{}条".format(len(resultList)))
            return resultList

if __name__ == "__main__":
    wareHouse = Warehouse("科技 上海", 2)
    wareHouse.initSpider()